package com.etc.controller;

import com.etc.entity.Categorys;
import com.etc.entity.Cinemas;
import com.etc.entity.Showings;
import com.etc.entity.Types;
import com.etc.service.ShowingServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/showings")
public class ShowingController {
    @Autowired
    ShowingServiceImpl showingServiceImpl;

    @RequestMapping("/queryAllCin")
    @ResponseBody
    public List<Cinemas> queryAllCin() {
        List<Cinemas> cinemas = showingServiceImpl.queryAllCin();
        return cinemas;
    }

    @RequestMapping("/queryAllType")
    @ResponseBody
    public List<Types> queryAllType() {
        List<Types> list = showingServiceImpl.queryAllType();
        return list;
    }

    @RequestMapping("/addShowing")
    public String te(String showing_data, Integer cina, Integer mov) {
        Integer seats = showingServiceImpl.querySeats(cina);
        boolean b = showingServiceImpl.addShowing(new Showings(showing_data, seats, cina, mov));
        if (b) {
            return "back/showingList";
        } else {
            return "back/addShowing";
        }
    }

    @RequestMapping("/queryAll")
    @ResponseBody
    public PageInfo<Showings> queryAll(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        PageInfo<Showings> pageInfo = showingServiceImpl.queryAll(pageNum, pageSize);
        return pageInfo;
    }

    @RequestMapping("/queryAllCint")
    @ResponseBody
    public PageInfo queryAllCint(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        PageInfo<Cinemas> pageInfo = showingServiceImpl.queryAllCint(pageNum, pageSize);
        return pageInfo;
    }

    @RequestMapping("/addCinema")
    public String addCinema(String cinema_name, Integer cinema_seat, Integer ctype) {
        boolean b = showingServiceImpl.addCinema(new Cinemas(cinema_name, cinema_seat, ctype));
        if (b) {
            return "back/cinemasList";
        } else {
            return "back/addCinemas";
        }
    }

    @RequestMapping("/addType")
    public String addType(String type_name) {
        boolean b = showingServiceImpl.addType(new Types(type_name));
        if (b) {
            return "back/addCinemas";
        } else {
            return "back/addType";
        }
    }

    @RequestMapping("/queryAllCate")
    @ResponseBody
    public List<Categorys> queryAllCate() {
        List<Categorys> list = showingServiceImpl.queryAllCate();
        return list;
    }

    @RequestMapping("/addCate")
    public String addCate(String category_name) {
        boolean b = showingServiceImpl.addCate(new Categorys(category_name));
        if (b) {
            return "back/addMovies";
        } else {
            return "back/addCate";
        }
    }

    @RequestMapping("/delCinema")
    @ResponseBody
    public boolean delCinema(Integer cinema_no) {
        boolean b = showingServiceImpl.delCinema(cinema_no);
        return b;
    }

    @RequestMapping("/delShowing")
    @ResponseBody
    public boolean delShowing(Integer showing_no) {
        boolean b = showingServiceImpl.delShowing(showing_no);
        return b;
    }
}
